<template>
    <div class="edit-popup">
        <popup
            ref="popupRef"
            :title="popupTitle"
            :async="true"
            width="350px"
            :clickModalClose="true"
            @confirm="handleSubmit"
            @close="handleClose"
            :confirmButtonText="false"
        >
            <h3>真实姓名：{{formData.realName}}</h3>
            <h3>账号：{{formData.username}}</h3>
            <h3>银行：{{formData.bankName}}</h3>
            <h3>银行卡号：{{formData.cardNumber}}</h3>
            <h3>银行卡绑定实名：{{formData.bankUserName}}</h3>
            <h3>银行卡绑定手机号：{{formData.bankMobile}}</h3>
            <h3>申请时间：{{formData.createTimeStr}}</h3>
            <h3>审核时间：{{formData.checkTimeStr}}</h3>
            <h3>审核人：{{formData.checkUserName}}</h3>
            <h3>审核结果：{{statusStr}}</h3>
            <h3>备注信息：{{formData.remark}}</h3>
        </popup>
    </div>
</template>
<script lang="ts" setup>
import type { FormInstance } from 'element-plus'
import {  withdrawEdit, withdrawAdd, withdrawDetail } from '@/api/withdraw'
import Popup from '@/components/popup/index.vue'
import feedback from '@/utils/feedback'
import type { PropType } from 'vue'
import {computed} from "vue";
let aa = defineProps({
    dictData: {
        type: Object as PropType<Record<string, any[]>>,
        default: () => ({})
    }
})
const emit = defineEmits(['success', 'close'])
const formRef = shallowRef<FormInstance>()
const popupRef = shallowRef<InstanceType<typeof Popup>>()
const mode = ref('add')
const popupTitle = ref('详情')

console.log(aa.dictData.withdraw_status);

let statusStr = computed(() =>{
    let array  = aa.dictData.withdraw_status
    console.log(formData.status)
    const newArr = array.filter((item) => {
        return item.value == formData.status
    })
    let dic = newArr.at(0);
    if (dic !== undefined) {
        return dic.name;
    } else {
        return "";
    }
})

const formData = reactive({
    id: '',
    userId: '',
    amount: '',
    cardId: '',
    checkTime: '',
    checkUser: '',
    status: '',
    tradeNo: '',
    remark: '',
    realName: '',
    mobile: '',
    username: '',
    bankUserName: '',
    cardNumber: '',
    bankName: '',
    bankMobile: '',
    createTimeStr: '',
    checkTimeStr: '',
    checkUserName: '',
})

const handleSubmit = async () => {
    await formRef.value?.validate()
    const data: any = { ...formData }
    mode.value == 'edit' ? await withdrawEdit(data) : await withdrawAdd(data)
    popupRef.value?.close()
    feedback.msgSuccess('操作成功')
    emit('success')
}

const open = (type = 'add') => {
    mode.value = type
    popupRef.value?.open()
}

const setFormData = async (data: Record<string, any>) => {
    for (const key in formData) {
        if (data[key] != null && data[key] != undefined) {
            //@ts-ignore
            formData[key] = data[key]
        }
    }
}

const getDetail = async (row: Record<string, any>) => {
    const data = await withdrawDetail({
        id: row.id
    })
    setFormData(data)
}

const handleClose = () => {
    emit('close')
}

defineExpose({
    open,
    setFormData,
    getDetail
})
</script>
